package Classes.GameViews.ViewDisplayers.MapTargets// ActionScript file
{
	import Classes.GameDatas.GD_Building_Func;
	import Classes.GameDatas.GD_Player;
	import Classes.GameUtils.GU_Sound;
	import Classes.GameUtils.GU_dealPower;
	import Classes.GameViews.GV_Map;
	import Classes.GameViews.ViewIcons.ViewIcon;
	import Classes.GameViews.ViewPanels.VP_Main;
	import Classes.GameViews.ViewPanels.VP_Make;
	import Classes.GameViews.ViewPanels.VP_errorPanel;
	import Classes.GameViews.ViewScenes.VS_Main;
	
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;

	public class MT_Building_Func extends MT_Building
	{
		private var _cannotSetSign:Boolean;/*无法放置标记*/
		public function MT_Building_Func(buildingFuncData:GD_Building_Func):void
		{
			super(buildingFuncData);
			this.tmpSign=true;
		}
		
		/**
		 *创建一个功能建筑 
		 * @param creatData 数据对象
		 * @return 建筑对象
		 * 
		 */			
		public static function creat(creatData:GD_Building_Func):MT_Building_Func
		{
			var returnBuilding:MT_Building_Func;
			returnBuilding=new MT_Building_Func(creatData);
			return returnBuilding;
		}
		
		/**
		 *覆写对象被点击的方法 
		 * @param e
		 * 
		 */		
		override public function beClicked(e:MouseEvent):void
		{
			//如果是在好友家 则点击无效
			if(GD_Player.instance.character.characterState==2)
			{
				return;
			}
			if(GV_Map.instance.buildMode==GV_Map.MOVEMODE)
			{
				GU_Sound.instance.playCommSound("Button_Building_Up");
				this.buildingFuncData.beSetting();
			}
			else if(GV_Map.instance.buildMode==GV_Map.CLEANMODE)
			{
				this.buildingFuncData.beCleaning();
				GU_Sound.instance.playCommSound("Button_Building_Delete");

//				VP_Main.instance.buildReShowHandler(null);
				
				
			}else if(GV_Map.instance.buildMode==GV_Map.CANNOTBUILDMODE)
			{
				//如果是主建筑  或者 合成数据不为空的  就可以点击弹出 合成或者拓地面板
				
				if((this.buildingFuncData.buildingType==40102001 || this.buildingFuncData.ztFunType==40103001 ||this.buildingFuncData.ztFunType==40104001 ||this.buildingFuncData.ztFunType==40105001) && !GU_dealPower.instance.isHavePower(10000207))//系统权限---点击研究所
				{
					VP_errorPanel.instance.noPowerMsg();
					return;
				}
				
				if(this.buildingFuncData.buildingType==40106001 && !GU_dealPower.instance.isHavePower(10000211))
				{
					VP_errorPanel.instance.noPowerMsg();
					return;
				}
				
				
				if(this.buildingFuncData.buildingType==40101001 && !GU_dealPower.instance.isHavePower(10000212))
				{
					VP_errorPanel.instance.noPowerMsg();
					return;
				}
				
				if(this.buildingFuncData.ztFunType==401)
				{
					var currectLv:int=this.buildingFuncData.buildingLv;
					var nextTmpOjb:Object=GD_Building_Func.buildingsConfigObj[this.buildingFuncData.buildingType].lvData[(currectLv+1)];
					//升级的数据  获取当前建筑的信息
					var tmpObj:Object=null;
					if(null!=nextTmpOjb)
					{
						tmpObj=GD_Building_Func.buildingsConfigObj[this.buildingFuncData.buildingType].lvData[currectLv];
						var ds:DisplayObject=ViewIcon.creat({sourceName:tmpObj.buildingPicSource,picName:tmpObj.itemPic});
						tmpObj.buildIcon=ds;
						tmpObj.taskType=nextTmpOjb.buildingItemType;
						tmpObj.BLV=currectLv;
						tmpObj.nextDes=nextTmpOjb.description;
					}
					VP_Make.instance.openBuildWin(VS_Main.instance,this.buildingFuncData.buildingType,tmpObj,currectLv);
				}
				
			}
		}
		
		/**
		 *恢复位置 
		 * 
		 */		
		public function resetPosition():void
		{
			if(this.mapGrid)
			{
				GV_Map.instance.addTarget(this,this.mapGrid);
			}
		}
		
		/*getter & setter*/
		public function get cannotSetSign():Boolean
		{
			return _cannotSetSign;
		}
		
		public function set cannotSetSign(value:Boolean):void
		{
			_cannotSetSign = value;
		}
		
		public function get buildingFuncData():GD_Building_Func
		{
			return this.buildingData as GD_Building_Func;
		}
		
		override public function get selectPriority():int
		{
			return 12;
		}
	}
}